#include <Utils.hpp>
#include <iostream>
#include <Network.hpp>
#include <thread>
class Game
{
private:
    Network net;
    bool m_server = false;
    bool con_closed = false;
    char map[225];
    int player;
    const int win_width = 800;
    const int win_height = 600;
    const int board_size = 600;
    const int padding = 20;
    const int row = 15;
    const float block_size = (board_size - 2 * padding) / (row - 1);
    const int line_width = 3;
    const float chess_size = block_size / 1.2;
    const int true_size = 600 - 2 * padding;
    bool win;
    bool myturn=true;
    int x;
    int y;
    int win_draw_info[5];
    int down =-1;
    int last_step=-1;
    char text_msg[0xff]={0};
    int touch_count=0;
    SDL_Renderer *render =nullptr;
    SDL_Window *window =nullptr;
    bool exited=false;
    std::thread th_timer;
public:
    Game(/* args */) = default;
    ~Game();

    int rest_time=0;
    int default_time=15;

    Network &getNetwork();
    SOCKET transfrom_socket;

    int run();
    int mainMenu();
    int server();
    int cilent();
    int gameLoop();
    void gameRender();
    void drawBoard();
    void mouseHover();

private:
    void static thread_recv(Game *gm, SOCKET socket);

    bool check_win(int down, int player);
    int contact_count(int player, int down, int dir[2], bool reverse);
    void chess_down();
    enum
{
    CHESS_WHITE = -1,
    CHESS_NULL,
    CHESS_BLACK
};
};